import { defineStore } from 'pinia'

export const useAppStore = defineStore('app', {
  state: () => ({
    language: localStorage.getItem('language') || 'zh-CN',
    menuPosition: localStorage.getItem('menuPosition') || 'aside',
    primaryColor: localStorage.getItem('primaryColor') || '#409EFF',
    isDarkMode: localStorage.getItem('isDarkMode') === 'true',
    showLogo: localStorage.getItem('showLogo') !== 'false',
    showTagsView: localStorage.getItem('showTagsView') !== 'false',
    menuBgColor: localStorage.getItem('menuBgColor') || '#001529',
    menuTextColor: localStorage.getItem('menuTextColor') || '#ffffff',
    menuActiveTextColor: localStorage.getItem('menuActiveTextColor') || '#409EFF',
    subMenuBgColor: localStorage.getItem('subMenuBgColor') || '#000c17'
  }),
  
  actions: {
    setLanguage(lang) {
      this.language = lang
      localStorage.setItem('language', lang)
    },

    setLayoutSettings(settings) {
      Object.entries(settings).forEach(([key, value]) => {
        this[key] = value
        localStorage.setItem(key, typeof value === 'boolean' ? value.toString() : value)
      })
    }
  }
}) 